package cn.sytton.taffe.code.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

/**
 * 字段Entity
 *
 * @author skyrock
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ColumnEntity {
    private String tableName;
    private String name;
    private String defaultValue;
    private String dataType;
    private Boolean isPri;
    private String comment;
    private String primaryColumn;
    private String isNullAble;

    private String javaType;
    private String tsType;

    //数据库的数据类型对应Java类型和ts类型
    private final static Map<String, String[]> MAP_DATATYPE = new HashMap<>();
    static {
        MAP_DATATYPE.put("varchar", new String[]{"String", "string"});
        MAP_DATATYPE.put("longtext", new String[]{"String", "string"});
        MAP_DATATYPE.put("text", new String[]{"String", "string"});
        MAP_DATATYPE.put("char", new String[]{"String", "string"});
        MAP_DATATYPE.put("tinyint", new String[]{"Boolean", "number"});
        MAP_DATATYPE.put("bit", new String[]{"Boolean", "number"});
        MAP_DATATYPE.put("int", new String[]{"Integer", "number"});
        MAP_DATATYPE.put("integer", new String[]{"Integer", "number"});
        MAP_DATATYPE.put("bigint", new String[]{"long", "number"});
        MAP_DATATYPE.put("decimal", new String[]{"BigDecimal", "number"});
        MAP_DATATYPE.put("float", new String[]{"Float", "number"});
        MAP_DATATYPE.put("double", new String[]{"Double", "number"});
        MAP_DATATYPE.put("timestamp", new String[]{"Timestamp", "string"});
        MAP_DATATYPE.put("datetime", new String[]{"Timestamp", "string"});
        MAP_DATATYPE.put("date", new String[]{"Date", "string"});
        MAP_DATATYPE.put("time", new String[]{"Time", "string"});
        MAP_DATATYPE.put("year", new String[]{"Date", "string"});
        MAP_DATATYPE.put("blob", new String[]{"String", "string"});
    }

    public String getJavaType() {
        return MAP_DATATYPE.get(this.getDataType().toLowerCase())[0];
    }

    public String getTsType() {
        return MAP_DATATYPE.get(this.getDataType().toLowerCase())[1];
    }
}
